<?php

/**
 * 代理商
 *
 * @package		Hooloo framework
 * @author 		Bill
 * @copyright 	Hooloo Co.,Ltd
 * @version		1.0
 * @release		2017.05.08
 */
defined('BASEPATH') OR exit('No direct script access allowed');

class Agent extends Controller {
	public function __construct() {
		parent::__construct();
	}
	
	/**
     * 列表
     */
	public function index() {
		//查询记录
		$aid = $_SESSION["agent"]["id"];
		if (IS_POST) {
			//修改密码
			$password = isset($_POST["password"]) ? $_POST["password"] : "";
			$repassword = isset($_POST["repassword"]) ? $_POST["repassword"] : "";
			$domain = isset($_POST["domain"]) ? $_POST["domain"] : "";
			$mobile = isset($_POST["mobile"]) ? $_POST["mobile"] : "";
			
			//更新信息
			if ($password) {
				if (strlen($password) < 6 || strlen($password) > 12) {
					ajax_return(0, "密码长度6至12位字符");
				} elseif ($password != $repassword) {
					ajax_return(0, "两次密码不一致");
				}
				
				$password = md5($password);
				$p_sql = "password = '$password', ";
			} else {
				$p_sql = "";
			}
			$sql = "update agent set " . $p_sql . " domain = '$domain', mobile = '$mobile' where id = $aid";
			$this->db->query($sql);
			
			ajax_return(1, "密码修改成功");
		}
		
		$sql = "select * from agent where id = $aid";
		$result = $this->db->query($sql)->row_array();
		
		$this->assign("result", $result);
		$this->display();
	}
}
